home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-01-09 | 3.0 KB | 90 lines | [TEXT/MPS ] |
- #--------------------------------------------------------------------------------------------------------------------------------------------------- #
- # CapFirst
- # MPW Shell Script
- # Written by Gina Cherry • September 16,1991
- # Copyright: © 1991 by Apple Computer, Inc., all rights reserved.
- #
- # Usage: CapFirst [file]
- #
- # Function:
- # CapFirst capitalizes the first character of each line of a text file. CapFirst skips over blanks
- # and tabs. If the first character is not a letter, no change occurs.
- #
- # Note: CapFirst can be added to the Edit menu with the following command:
- #
- # AddMenu Edit 'CapFirst/6' 'CapFirst "{Active}"'
- #---------------------------------------------------------------------------------------------------------------------------------------------------
-
- # If there is more than 1 parameter, write error message and exit script.
- If {#} > 1
- Echo "###Usage: {0} File"
- Exit 1
- End >> Dev:StdErr
-
- # Do not exit on error.
- Set Exit 0
-
- # Searches should be case sensitive.
- Set CaseSensitive 1
-
- # If a parameter is given, File is set to the parameter. Otherwise, File is the target file.
- If {#} == 1
- Set File "{1}"
- Else
- Set File "{Target}"
- End
-
- # Record whether fName is already open.
- Set fullName "`Files -i -f "{File}" ≥ Dev:Null`"
- Set wasOpen `Evaluate "∂`Windows∂`" =~ /≈{fullName}≈/`
-
- # Open input file. Since diagnostic output from Open command is not needed, redirect it to bit bucket.
- Open "{File}" ≥ Dev:Null
-
- # If input file does not exist, exit script.
- If {Status} != 0
- Echo "###{0}: {File} is not a valid file."
- Exit 1
- End >> Dev:StdErr
-
- # Mark currently selected text to restore state of window at end of script.
- Mark -y § {0}.Selection "{File}"
-
- # Position cursor at beginning of input file.
- Find • "{File}"
-
- # Save value of NewWindowRect to restore later.
- Set OldWindowRect "{NewWindowRect}"
-
- # Loop through lines in input file.
- Loop
-
- # Position cursor at beginning of the current line in input file.
- Find /•[ ∂t]*?/ "{File}" || Break
-
- (Evaluate "`Catenate "{File}".§`" =~ /([ ∂t]*)®1(?)®2≈/) > Dev:Null || Break
-
- # Check whether the selected character is a lowercase letter.
- # Note: Diagnostic output for the entire If statement is discarded because the If statement will
- # produce an error message if the selected text in the input file is a parenthesis. This occurs
- # because the shell interprets the character as an unmatched parenthesis.
- If "{®2}" =~ /[a-z]/
- # If so, change it to an uppercase letter and echo the change to the temporary file,
- # overwriting the file's contents.
- echo -n "{®1}{®2}" | Translate a-z A-Z > "{File}.§"
-
- End ≥ Dev:Null
-
- End
-
- # Select the text that was originally selected in the input file.
- Find {0}.Selection "{File}"
-
- # Delete the marker from the input file.
- Unmark {0}.Selection "{File}"
-
- # If the input file was not open to start with, close the file and save changes.
- If !"{wasOpen}"
- Close -y "{File}"
- End
-